﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Xml;
using System.Windows;

namespace GnToolMain
{
	public class FileDialogButton : Button, Layout.IControlLayout
	{
        public enum eDialogType
        {
            FILE_DIALOG,
            FOLDER_DIALOG,
        }

        public eDialogType DialogType
        {
            get { return (eDialogType)GetValue( ItemsSourceProperty ); }
            set { SetValue( ItemsSourceProperty, value ); }
        }

        public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
           "DialogType", typeof( eDialogType ), typeof( FileDialogButton ), new PropertyMetadata( eDialogType.FILE_DIALOG ) );
           //ComboBox.ItemsSourceProperty.AddOwner(
           //typeof( FileDialogButton ),new FrameworkPropertyMetadata( null, NotifyPropertyChangeForRefreshContent ) );

        String mLastSelectPath;

		public FileDialogButton() : base()
		{
            this.Click += new RoutedEventHandler( FileDialogButton_Click );
		}

        void FileDialogButton_Click( object sender, RoutedEventArgs e )
        {
            switch( DialogType )
            {
            case eDialogType.FILE_DIALOG:
                {
                    System.Windows.Forms.FileDialog dlg = new System.Windows.Forms.SaveFileDialog();
                    if( dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK )
                    {                        
                    }

                }
                break;
            case eDialogType.FOLDER_DIALOG:
                {
                }
                break;
            }
        }

		public void SaveLayout( XmlWriter writer, Object control )
		{
            if( Name.Length <= 0 )
                return;

            try
            {
                writer.WriteStartElement( Name );
                writer.WriteAttributeString( "controlType", this.ToString() );
                writer.WriteElementString( "lastFilePath", mLastSelectPath );
                writer.WriteEndElement();
            }
            catch
            {
            	
            }
		}

		public void LoadLayout( XmlReader reader, Object control )
		{

		}

		public bool IsMineControl( Object control )
		{
			return true;
		}
	}
}
